// Copyright (c) Lawrence Livermore National Security, LLC and other VisIt
// Project developers.  See the top-level LICENSE file for dates and other
// details.  No copyright assignment is required to contribute to VisIt.

#include <PyPickVarInfo.h>
#include <ObserverToCallback.h>
#include <stdio.h>
#include <Py2and3Support.h>

// ****************************************************************************
// Module: PyPickVarInfo
//
// Purpose:
//   This class contains PickVarInfo.
//
// Note:       Autogenerated by xml2python. Do not modify by hand!
//
// Programmer: xml2python
// Creation:   omitted
//
// ****************************************************************************

//
// This struct contains the Python type information and a PickVarInfo.
//
struct PickVarInfoObject
{
    PyObject_HEAD
    PickVarInfo *data;
    bool        owns;
    PyObject   *parent;
};

//
// Internal prototypes
//
static PyObject *NewPickVarInfo(int);
std::string
PyPickVarInfo_ToString(const PickVarInfo *atts, const char *prefix, const bool forLogging)
{
    std::string str;
    char tmpStr[1000];

    snprintf(tmpStr, 1000, "%svariableName = \"%s\"\n", prefix, atts->GetVariableName().c_str());
    str += tmpStr;
    snprintf(tmpStr, 1000, "%svariableType = \"%s\"\n", prefix, atts->GetVariableType().c_str());
    str += tmpStr;
    {   const stringVector &names = atts->GetNames();
        snprintf(tmpStr, 1000, "%snames = (", prefix);
        str += tmpStr;
        for(size_t i = 0; i < names.size(); ++i)
        {
            snprintf(tmpStr, 1000, "\"%s\"", names[i].c_str());
            str += tmpStr;
            if(i < names.size() - 1)
            {
                snprintf(tmpStr, 1000, ", ");
                str += tmpStr;
            }
        }
        snprintf(tmpStr, 1000, ")\n");
        str += tmpStr;
    }
    {   const doubleVector &values = atts->GetValues();
        snprintf(tmpStr, 1000, "%svalues = (", prefix);
        str += tmpStr;
        for(size_t i = 0; i < values.size(); ++i)
        {
            snprintf(tmpStr, 1000, "%g", values[i]);
            str += tmpStr;
            if(i < values.size() - 1)
            {
                snprintf(tmpStr, 1000, ", ");
                str += tmpStr;
            }
        }
        snprintf(tmpStr, 1000, ")\n");
        str += tmpStr;
    }
    {   const stringVector &mixNames = atts->GetMixNames();
        snprintf(tmpStr, 1000, "%smixNames = (", prefix);
        str += tmpStr;
        for(size_t i = 0; i < mixNames.size(); ++i)
        {
            snprintf(tmpStr, 1000, "\"%s\"", mixNames[i].c_str());
            str += tmpStr;
            if(i < mixNames.size() - 1)
            {
                snprintf(tmpStr, 1000, ", ");
                str += tmpStr;
            }
        }
        snprintf(tmpStr, 1000, ")\n");
        str += tmpStr;
    }
    {   const doubleVector &mixValues = atts->GetMixValues();
        snprintf(tmpStr, 1000, "%smixValues = (", prefix);
        str += tmpStr;
        for(size_t i = 0; i < mixValues.size(); ++i)
        {
            snprintf(tmpStr, 1000, "%g", mixValues[i]);
            str += tmpStr;
            if(i < mixValues.size() - 1)
            {
                snprintf(tmpStr, 1000, ", ");
                str += tmpStr;
            }
        }
        snprintf(tmpStr, 1000, ")\n");
        str += tmpStr;
    }
    if(atts->GetMixVar())
        snprintf(tmpStr, 1000, "%smixVar = 1\n", prefix);
    else
        snprintf(tmpStr, 1000, "%smixVar = 0\n", prefix);
    str += tmpStr;
    const char *centering_names = "Nodal, Zonal, NONE";
    switch (atts->GetCentering())
    {
      case PickVarInfo::Nodal:
          snprintf(tmpStr, 1000, "%scentering = %sNodal  # %s\n", prefix, prefix, centering_names);
          str += tmpStr;
          break;
      case PickVarInfo::Zonal:
          snprintf(tmpStr, 1000, "%scentering = %sZonal  # %s\n", prefix, prefix, centering_names);
          str += tmpStr;
          break;
      case PickVarInfo::None:
          snprintf(tmpStr, 1000, "%scentering = %sNONE  # %s\n", prefix, prefix, centering_names);
          str += tmpStr;
          break;
      default:
          break;
    }

    snprintf(tmpStr, 1000, "%smiscMessage = \"%s\"\n", prefix, atts->GetMiscMessage().c_str());
    str += tmpStr;
    {   const intVector &numMatsPerZone = atts->GetNumMatsPerZone();
        snprintf(tmpStr, 1000, "%snumMatsPerZone = (", prefix);
        str += tmpStr;
        for(size_t i = 0; i < numMatsPerZone.size(); ++i)
        {
            snprintf(tmpStr, 1000, "%d", numMatsPerZone[i]);
            str += tmpStr;
            if(i < numMatsPerZone.size() - 1)
            {
                snprintf(tmpStr, 1000, ", ");
                str += tmpStr;
            }
        }
        snprintf(tmpStr, 1000, ")\n");
        str += tmpStr;
    }
    {   const stringVector &matNames = atts->GetMatNames();
        snprintf(tmpStr, 1000, "%smatNames = (", prefix);
        str += tmpStr;
        for(size_t i = 0; i < matNames.size(); ++i)
        {
            snprintf(tmpStr, 1000, "\"%s\"", matNames[i].c_str());
            str += tmpStr;
            if(i < matNames.size() - 1)
            {
                snprintf(tmpStr, 1000, ", ");
                str += tmpStr;
            }
        }
        snprintf(tmpStr, 1000, ")\n");
        str += tmpStr;
    }
    {   const intVector &numSpecsPerMat = atts->GetNumSpecsPerMat();
        snprintf(tmpStr, 1000, "%snumSpecsPerMat = (", prefix);
        str += tmpStr;
        for(size_t i = 0; i < numSpecsPerMat.size(); ++i)
        {
            snprintf(tmpStr, 1000, "%d", numSpecsPerMat[i]);
            str += tmpStr;
            if(i < numSpecsPerMat.size() - 1)
            {
                snprintf(tmpStr, 1000, ", ");
                str += tmpStr;
            }
        }
        snprintf(tmpStr, 1000, ")\n");
        str += tmpStr;
    }
    snprintf(tmpStr, 1000, "%sfloatFormat = \"%s\"\n", prefix, atts->GetFloatFormat().c_str());
    str += tmpStr;
    return str;
}

static PyObject *
PickVarInfo_Notify(PyObject *self, PyObject *args)
{
    PickVarInfoObject *obj = (PickVarInfoObject *)self;
    obj->data->Notify();
    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
PickVarInfo_SetVariableName(PyObject *self, PyObject *args)
{
    PickVarInfoObject *obj = (PickVarInfoObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged as first member of a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyUnicode_Check(packaged_args))
            args = packaged_args;
    }

    if (!PyUnicode_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a unicode string");
    }

    char const *val = PyUnicode_AsUTF8(args);
    std::string cval = std::string(val);

    if (val == 0 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as utf8 string");
    }

    Py_XDECREF(packaged_args);

    // Set the variableName in the object.
    obj->data->SetVariableName(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
PickVarInfo_GetVariableName(PyObject *self, PyObject *args)
{
    PickVarInfoObject *obj = (PickVarInfoObject *)self;
    PyObject *retval = PyString_FromString(obj->data->GetVariableName().c_str());
    return retval;
}

/*static*/ PyObject *
PickVarInfo_SetVariableType(PyObject *self, PyObject *args)
{
    PickVarInfoObject *obj = (PickVarInfoObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged as first member of a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyUnicode_Check(packaged_args))
            args = packaged_args;
    }

    if (!PyUnicode_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a unicode string");
    }

    char const *val = PyUnicode_AsUTF8(args);
    std::string cval = std::string(val);

    if (val == 0 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as utf8 string");
    }

    Py_XDECREF(packaged_args);

    // Set the variableType in the object.
    obj->data->SetVariableType(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
PickVarInfo_GetVariableType(PyObject *self, PyObject *args)
{
    PickVarInfoObject *obj = (PickVarInfoObject *)self;
    PyObject *retval = PyString_FromString(obj->data->GetVariableType().c_str());
    return retval;
}

/*static*/ PyObject *
PickVarInfo_SetNames(PyObject *self, PyObject *args)
{
    PickVarInfoObject *obj = (PickVarInfoObject *)self;

    stringVector vec;

    if (PyUnicode_Check(args))
    {
        char const *val = PyUnicode_AsUTF8(args);
        std::string cval = std::string(val);
        if (val == 0 && PyErr_Occurred())
        {
            PyErr_Clear();
            return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ string");
        }
        vec.resize(1);
        vec[0] = cval;
    }
    else if (PySequence_Check(args))
    {
        vec.resize(PySequence_Size(args));
        for (Py_ssize_t i = 0; i < PySequence_Size(args); i++)
        {
            PyObject *item = PySequence_GetItem(args, i);

            if (!PyUnicode_Check(item))
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_TypeError, "arg %d is not a unicode string", (int) i);
            }

            char const *val = PyUnicode_AsUTF8(item);
            std::string cval = std::string(val);

            if (val == 0 && PyErr_Occurred())
            {
                Py_DECREF(item);
                PyErr_Clear();
                return PyErr_Format(PyExc_TypeError, "arg %d not interpretable as C++ string", (int) i);
            }
            Py_DECREF(item);

            vec[i] = cval;
        }
    }
    else
        return PyErr_Format(PyExc_TypeError, "arg(s) must be one or more string(s)");

    obj->data->GetNames() = vec;
    // Mark the names in the object as modified.
    obj->data->SelectNames();

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
PickVarInfo_GetNames(PyObject *self, PyObject *args)
{
    PickVarInfoObject *obj = (PickVarInfoObject *)self;
    // Allocate a tuple the with enough entries to hold the names.
    const stringVector &names = obj->data->GetNames();
    PyObject *retval = PyTuple_New(names.size());
    for(size_t i = 0; i < names.size(); ++i)
        PyTuple_SET_ITEM(retval, i, PyString_FromString(names[i].c_str()));
    return retval;
}

/*static*/ PyObject *
PickVarInfo_SetValues(PyObject *self, PyObject *args)
{
    PickVarInfoObject *obj = (PickVarInfoObject *)self;

    doubleVector vec;

    if (PyNumber_Check(args))
    {
        double val = PyFloat_AsDouble(args);
        double cval = double(val);
        if (val == -1 && PyErr_Occurred())
        {
            PyErr_Clear();
            return PyErr_Format(PyExc_TypeError, "number not interpretable as C++ double");
        }
        if (fabs(double(val))>1.5E-7 && fabs((double(double(cval))-double(val))/double(val))>1.5E-7)
            return PyErr_Format(PyExc_ValueError, "number not interpretable as C++ double");
        vec.resize(1);
        vec[0] = cval;
    }
    else if (PySequence_Check(args) && !PyUnicode_Check(args))
    {
        vec.resize(PySequence_Size(args));
        for (Py_ssize_t i = 0; i < PySequence_Size(args); i++)
        {
            PyObject *item = PySequence_GetItem(args, i);

            if (!PyNumber_Check(item))
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_TypeError, "arg %d is not a number type", (int) i);
            }

            double val = PyFloat_AsDouble(item);
            double cval = double(val);

            if (val == -1 && PyErr_Occurred())
            {
                Py_DECREF(item);
                PyErr_Clear();
                return PyErr_Format(PyExc_TypeError, "arg %d not interpretable as C++ double", (int) i);
            }
            if (fabs(double(val))>1.5E-7 && fabs((double(double(cval))-double(val))/double(val))>1.5E-7)
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_ValueError, "arg %d not interpretable as C++ double", (int) i);
            }
            Py_DECREF(item);

            vec[i] = cval;
        }
    }
    else
        return PyErr_Format(PyExc_TypeError, "arg(s) must be one or more doubles");

    obj->data->GetValues() = vec;
    // Mark the values in the object as modified.
    obj->data->SelectValues();

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
PickVarInfo_GetValues(PyObject *self, PyObject *args)
{
    PickVarInfoObject *obj = (PickVarInfoObject *)self;
    // Allocate a tuple the with enough entries to hold the values.
    const doubleVector &values = obj->data->GetValues();
    PyObject *retval = PyTuple_New(values.size());
    for(size_t i = 0; i < values.size(); ++i)
        PyTuple_SET_ITEM(retval, i, PyFloat_FromDouble(values[i]));
    return retval;
}

/*static*/ PyObject *
PickVarInfo_SetMixNames(PyObject *self, PyObject *args)
{
    PickVarInfoObject *obj = (PickVarInfoObject *)self;

    stringVector vec;

    if (PyUnicode_Check(args))
    {
        char const *val = PyUnicode_AsUTF8(args);
        std::string cval = std::string(val);
        if (val == 0 && PyErr_Occurred())
        {
            PyErr_Clear();
            return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ string");
        }
        vec.resize(1);
        vec[0] = cval;
    }
    else if (PySequence_Check(args))
    {
        vec.resize(PySequence_Size(args));
        for (Py_ssize_t i = 0; i < PySequence_Size(args); i++)
        {
            PyObject *item = PySequence_GetItem(args, i);

            if (!PyUnicode_Check(item))
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_TypeError, "arg %d is not a unicode string", (int) i);
            }

            char const *val = PyUnicode_AsUTF8(item);
            std::string cval = std::string(val);

            if (val == 0 && PyErr_Occurred())
            {
                Py_DECREF(item);
                PyErr_Clear();
                return PyErr_Format(PyExc_TypeError, "arg %d not interpretable as C++ string", (int) i);
            }
            Py_DECREF(item);

            vec[i] = cval;
        }
    }
    else
        return PyErr_Format(PyExc_TypeError, "arg(s) must be one or more string(s)");

    obj->data->GetMixNames() = vec;
    // Mark the mixNames in the object as modified.
    obj->data->SelectMixNames();

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
PickVarInfo_GetMixNames(PyObject *self, PyObject *args)
{
    PickVarInfoObject *obj = (PickVarInfoObject *)self;
    // Allocate a tuple the with enough entries to hold the mixNames.
    const stringVector &mixNames = obj->data->GetMixNames();
    PyObject *retval = PyTuple_New(mixNames.size());
    for(size_t i = 0; i < mixNames.size(); ++i)
        PyTuple_SET_ITEM(retval, i, PyString_FromString(mixNames[i].c_str()));
    return retval;
}

/*static*/ PyObject *
PickVarInfo_SetMixValues(PyObject *self, PyObject *args)
{
    PickVarInfoObject *obj = (PickVarInfoObject *)self;

    doubleVector vec;

    if (PyNumber_Check(args))
    {
        double val = PyFloat_AsDouble(args);
        double cval = double(val);
        if (val == -1 && PyErr_Occurred())
        {
            PyErr_Clear();
            return PyErr_Format(PyExc_TypeError, "number not interpretable as C++ double");
        }
        if (fabs(double(val))>1.5E-7 && fabs((double(double(cval))-double(val))/double(val))>1.5E-7)
            return PyErr_Format(PyExc_ValueError, "number not interpretable as C++ double");
        vec.resize(1);
        vec[0] = cval;
    }
    else if (PySequence_Check(args) && !PyUnicode_Check(args))
    {
        vec.resize(PySequence_Size(args));
        for (Py_ssize_t i = 0; i < PySequence_Size(args); i++)
        {
            PyObject *item = PySequence_GetItem(args, i);

            if (!PyNumber_Check(item))
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_TypeError, "arg %d is not a number type", (int) i);
            }

            double val = PyFloat_AsDouble(item);
            double cval = double(val);

            if (val == -1 && PyErr_Occurred())
            {
                Py_DECREF(item);
                PyErr_Clear();
                return PyErr_Format(PyExc_TypeError, "arg %d not interpretable as C++ double", (int) i);
            }
            if (fabs(double(val))>1.5E-7 && fabs((double(double(cval))-double(val))/double(val))>1.5E-7)
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_ValueError, "arg %d not interpretable as C++ double", (int) i);
            }
            Py_DECREF(item);

            vec[i] = cval;
        }
    }
    else
        return PyErr_Format(PyExc_TypeError, "arg(s) must be one or more doubles");

    obj->data->GetMixValues() = vec;
    // Mark the mixValues in the object as modified.
    obj->data->SelectMixValues();

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
PickVarInfo_GetMixValues(PyObject *self, PyObject *args)
{
    PickVarInfoObject *obj = (PickVarInfoObject *)self;
    // Allocate a tuple the with enough entries to hold the mixValues.
    const doubleVector &mixValues = obj->data->GetMixValues();
    PyObject *retval = PyTuple_New(mixValues.size());
    for(size_t i = 0; i < mixValues.size(); ++i)
        PyTuple_SET_ITEM(retval, i, PyFloat_FromDouble(mixValues[i]));
    return retval;
}

/*static*/ PyObject *
PickVarInfo_SetMixVar(PyObject *self, PyObject *args)
{
    PickVarInfoObject *obj = (PickVarInfoObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    bool cval = bool(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ bool");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ bool");
    }

    Py_XDECREF(packaged_args);

    // Set the mixVar in the object.
    obj->data->SetMixVar(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
PickVarInfo_GetMixVar(PyObject *self, PyObject *args)
{
    PickVarInfoObject *obj = (PickVarInfoObject *)self;
    PyObject *retval = PyInt_FromLong(obj->data->GetMixVar()?1L:0L);
    return retval;
}

/*static*/ PyObject *
PickVarInfo_SetCentering(PyObject *self, PyObject *args)
{
    PickVarInfoObject *obj = (PickVarInfoObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    int cval = int(val);

    if ((val == -1 && PyErr_Occurred()) || long(cval) != val)
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ int");
    }

    if (cval < 0 || cval >= 3)
    {
        std::stringstream ss;
        ss << "An invalid centering value was given." << std::endl;
        ss << "Valid values are in the range [0,2]." << std::endl;
        ss << "You can also use the following symbolic names:";
        ss << " Nodal";
        ss << ", Zonal";
        ss << ", None";
        return PyErr_Format(PyExc_ValueError, ss.str().c_str());
    }

    Py_XDECREF(packaged_args);

    // Set the centering in the object.
    obj->data->SetCentering(PickVarInfo::Centering(cval));

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
PickVarInfo_GetCentering(PyObject *self, PyObject *args)
{
    PickVarInfoObject *obj = (PickVarInfoObject *)self;
    PyObject *retval = PyInt_FromLong(long(obj->data->GetCentering()));
    return retval;
}

/*static*/ PyObject *
PickVarInfo_SetMiscMessage(PyObject *self, PyObject *args)
{
    PickVarInfoObject *obj = (PickVarInfoObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged as first member of a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyUnicode_Check(packaged_args))
            args = packaged_args;
    }

    if (!PyUnicode_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a unicode string");
    }

    char const *val = PyUnicode_AsUTF8(args);
    std::string cval = std::string(val);

    if (val == 0 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as utf8 string");
    }

    Py_XDECREF(packaged_args);

    // Set the miscMessage in the object.
    obj->data->SetMiscMessage(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
PickVarInfo_GetMiscMessage(PyObject *self, PyObject *args)
{
    PickVarInfoObject *obj = (PickVarInfoObject *)self;
    PyObject *retval = PyString_FromString(obj->data->GetMiscMessage().c_str());
    return retval;
}

/*static*/ PyObject *
PickVarInfo_SetNumMatsPerZone(PyObject *self, PyObject *args)
{
    PickVarInfoObject *obj = (PickVarInfoObject *)self;

    intVector vec;

    if (PyNumber_Check(args))
    {
        long val = PyLong_AsLong(args);
        int cval = int(val);
        if (val == -1 && PyErr_Occurred())
        {
            PyErr_Clear();
            return PyErr_Format(PyExc_TypeError, "number not interpretable as C++ int");
        }
        if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
            return PyErr_Format(PyExc_ValueError, "number not interpretable as C++ int");
        vec.resize(1);
        vec[0] = cval;
    }
    else if (PySequence_Check(args) && !PyUnicode_Check(args))
    {
        vec.resize(PySequence_Size(args));
        for (Py_ssize_t i = 0; i < PySequence_Size(args); i++)
        {
            PyObject *item = PySequence_GetItem(args, i);

            if (!PyNumber_Check(item))
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_TypeError, "arg %d is not a number type", (int) i);
            }

            long val = PyLong_AsLong(item);
            int cval = int(val);

            if (val == -1 && PyErr_Occurred())
            {
                Py_DECREF(item);
                PyErr_Clear();
                return PyErr_Format(PyExc_TypeError, "arg %d not interpretable as C++ int", (int) i);
            }
            if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_ValueError, "arg %d not interpretable as C++ int", (int) i);
            }
            Py_DECREF(item);

            vec[i] = cval;
        }
    }
    else
        return PyErr_Format(PyExc_TypeError, "arg(s) must be one or more ints");

    obj->data->GetNumMatsPerZone() = vec;
    // Mark the numMatsPerZone in the object as modified.
    obj->data->SelectNumMatsPerZone();

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
PickVarInfo_GetNumMatsPerZone(PyObject *self, PyObject *args)
{
    PickVarInfoObject *obj = (PickVarInfoObject *)self;
    // Allocate a tuple the with enough entries to hold the numMatsPerZone.
    const intVector &numMatsPerZone = obj->data->GetNumMatsPerZone();
    PyObject *retval = PyTuple_New(numMatsPerZone.size());
    for(size_t i = 0; i < numMatsPerZone.size(); ++i)
        PyTuple_SET_ITEM(retval, i, PyInt_FromLong(long(numMatsPerZone[i])));
    return retval;
}

/*static*/ PyObject *
PickVarInfo_SetMatNames(PyObject *self, PyObject *args)
{
    PickVarInfoObject *obj = (PickVarInfoObject *)self;

    stringVector vec;

    if (PyUnicode_Check(args))
    {
        char const *val = PyUnicode_AsUTF8(args);
        std::string cval = std::string(val);
        if (val == 0 && PyErr_Occurred())
        {
            PyErr_Clear();
            return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ string");
        }
        vec.resize(1);
        vec[0] = cval;
    }
    else if (PySequence_Check(args))
    {
        vec.resize(PySequence_Size(args));
        for (Py_ssize_t i = 0; i < PySequence_Size(args); i++)
        {
            PyObject *item = PySequence_GetItem(args, i);

            if (!PyUnicode_Check(item))
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_TypeError, "arg %d is not a unicode string", (int) i);
            }

            char const *val = PyUnicode_AsUTF8(item);
            std::string cval = std::string(val);

            if (val == 0 && PyErr_Occurred())
            {
                Py_DECREF(item);
                PyErr_Clear();
                return PyErr_Format(PyExc_TypeError, "arg %d not interpretable as C++ string", (int) i);
            }
            Py_DECREF(item);

            vec[i] = cval;
        }
    }
    else
        return PyErr_Format(PyExc_TypeError, "arg(s) must be one or more string(s)");

    obj->data->GetMatNames() = vec;
    // Mark the matNames in the object as modified.
    obj->data->SelectMatNames();

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
PickVarInfo_GetMatNames(PyObject *self, PyObject *args)
{
    PickVarInfoObject *obj = (PickVarInfoObject *)self;
    // Allocate a tuple the with enough entries to hold the matNames.
    const stringVector &matNames = obj->data->GetMatNames();
    PyObject *retval = PyTuple_New(matNames.size());
    for(size_t i = 0; i < matNames.size(); ++i)
        PyTuple_SET_ITEM(retval, i, PyString_FromString(matNames[i].c_str()));
    return retval;
}

/*static*/ PyObject *
PickVarInfo_SetNumSpecsPerMat(PyObject *self, PyObject *args)
{
    PickVarInfoObject *obj = (PickVarInfoObject *)self;

    intVector vec;

    if (PyNumber_Check(args))
    {
        long val = PyLong_AsLong(args);
        int cval = int(val);
        if (val == -1 && PyErr_Occurred())
        {
            PyErr_Clear();
            return PyErr_Format(PyExc_TypeError, "number not interpretable as C++ int");
        }
        if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
            return PyErr_Format(PyExc_ValueError, "number not interpretable as C++ int");
        vec.resize(1);
        vec[0] = cval;
    }
    else if (PySequence_Check(args) && !PyUnicode_Check(args))
    {
        vec.resize(PySequence_Size(args));
        for (Py_ssize_t i = 0; i < PySequence_Size(args); i++)
        {
            PyObject *item = PySequence_GetItem(args, i);

            if (!PyNumber_Check(item))
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_TypeError, "arg %d is not a number type", (int) i);
            }

            long val = PyLong_AsLong(item);
            int cval = int(val);

            if (val == -1 && PyErr_Occurred())
            {
                Py_DECREF(item);
                PyErr_Clear();
                return PyErr_Format(PyExc_TypeError, "arg %d not interpretable as C++ int", (int) i);
            }
            if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_ValueError, "arg %d not interpretable as C++ int", (int) i);
            }
            Py_DECREF(item);

            vec[i] = cval;
        }
    }
    else
        return PyErr_Format(PyExc_TypeError, "arg(s) must be one or more ints");

    obj->data->GetNumSpecsPerMat() = vec;
    // Mark the numSpecsPerMat in the object as modified.
    obj->data->SelectNumSpecsPerMat();

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
PickVarInfo_GetNumSpecsPerMat(PyObject *self, PyObject *args)
{
    PickVarInfoObject *obj = (PickVarInfoObject *)self;
    // Allocate a tuple the with enough entries to hold the numSpecsPerMat.
    const intVector &numSpecsPerMat = obj->data->GetNumSpecsPerMat();
    PyObject *retval = PyTuple_New(numSpecsPerMat.size());
    for(size_t i = 0; i < numSpecsPerMat.size(); ++i)
        PyTuple_SET_ITEM(retval, i, PyInt_FromLong(long(numSpecsPerMat[i])));
    return retval;
}

/*static*/ PyObject *
PickVarInfo_SetFloatFormat(PyObject *self, PyObject *args)
{
    PickVarInfoObject *obj = (PickVarInfoObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged as first member of a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyUnicode_Check(packaged_args))
            args = packaged_args;
    }

    if (!PyUnicode_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a unicode string");
    }

    char const *val = PyUnicode_AsUTF8(args);
    std::string cval = std::string(val);

    if (val == 0 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as utf8 string");
    }

    Py_XDECREF(packaged_args);

    // Set the floatFormat in the object.
    obj->data->SetFloatFormat(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
PickVarInfo_GetFloatFormat(PyObject *self, PyObject *args)
{
    PickVarInfoObject *obj = (PickVarInfoObject *)self;
    PyObject *retval = PyString_FromString(obj->data->GetFloatFormat().c_str());
    return retval;
}



PyMethodDef PyPickVarInfo_methods[PICKVARINFO_NMETH] = {
    {"Notify", PickVarInfo_Notify, METH_VARARGS},
    {"SetVariableName", PickVarInfo_SetVariableName, METH_VARARGS},
    {"GetVariableName", PickVarInfo_GetVariableName, METH_VARARGS},
    {"SetVariableType", PickVarInfo_SetVariableType, METH_VARARGS},
    {"GetVariableType", PickVarInfo_GetVariableType, METH_VARARGS},
    {"SetNames", PickVarInfo_SetNames, METH_VARARGS},
    {"GetNames", PickVarInfo_GetNames, METH_VARARGS},
    {"SetValues", PickVarInfo_SetValues, METH_VARARGS},
    {"GetValues", PickVarInfo_GetValues, METH_VARARGS},
    {"SetMixNames", PickVarInfo_SetMixNames, METH_VARARGS},
    {"GetMixNames", PickVarInfo_GetMixNames, METH_VARARGS},
    {"SetMixValues", PickVarInfo_SetMixValues, METH_VARARGS},
    {"GetMixValues", PickVarInfo_GetMixValues, METH_VARARGS},
    {"SetMixVar", PickVarInfo_SetMixVar, METH_VARARGS},
    {"GetMixVar", PickVarInfo_GetMixVar, METH_VARARGS},
    {"SetCentering", PickVarInfo_SetCentering, METH_VARARGS},
    {"GetCentering", PickVarInfo_GetCentering, METH_VARARGS},
    {"SetMiscMessage", PickVarInfo_SetMiscMessage, METH_VARARGS},
    {"GetMiscMessage", PickVarInfo_GetMiscMessage, METH_VARARGS},
    {"SetNumMatsPerZone", PickVarInfo_SetNumMatsPerZone, METH_VARARGS},
    {"GetNumMatsPerZone", PickVarInfo_GetNumMatsPerZone, METH_VARARGS},
    {"SetMatNames", PickVarInfo_SetMatNames, METH_VARARGS},
    {"GetMatNames", PickVarInfo_GetMatNames, METH_VARARGS},
    {"SetNumSpecsPerMat", PickVarInfo_SetNumSpecsPerMat, METH_VARARGS},
    {"GetNumSpecsPerMat", PickVarInfo_GetNumSpecsPerMat, METH_VARARGS},
    {"SetFloatFormat", PickVarInfo_SetFloatFormat, METH_VARARGS},
    {"GetFloatFormat", PickVarInfo_GetFloatFormat, METH_VARARGS},
    {NULL, NULL}
};

//
// Type functions
//

static void
PickVarInfo_dealloc(PyObject *v)
{
   PickVarInfoObject *obj = (PickVarInfoObject *)v;
   if(obj->parent != 0)
       Py_DECREF(obj->parent);
   if(obj->owns)
       delete obj->data;
}

static PyObject *PickVarInfo_richcompare(PyObject *self, PyObject *other, int op);
PyObject *
PyPickVarInfo_getattr(PyObject *self, char *name)
{
    if(strcmp(name, "variableName") == 0)
        return PickVarInfo_GetVariableName(self, NULL);
    if(strcmp(name, "variableType") == 0)
        return PickVarInfo_GetVariableType(self, NULL);
    if(strcmp(name, "names") == 0)
        return PickVarInfo_GetNames(self, NULL);
    if(strcmp(name, "values") == 0)
        return PickVarInfo_GetValues(self, NULL);
    if(strcmp(name, "mixNames") == 0)
        return PickVarInfo_GetMixNames(self, NULL);
    if(strcmp(name, "mixValues") == 0)
        return PickVarInfo_GetMixValues(self, NULL);
    if(strcmp(name, "mixVar") == 0)
        return PickVarInfo_GetMixVar(self, NULL);
    if(strcmp(name, "centering") == 0)
        return PickVarInfo_GetCentering(self, NULL);
    if(strcmp(name, "Nodal") == 0)
        return PyInt_FromLong(long(PickVarInfo::Nodal));
    if(strcmp(name, "Zonal") == 0)
        return PyInt_FromLong(long(PickVarInfo::Zonal));
    if(strcmp(name, "None") == 0)
        return PyInt_FromLong(long(PickVarInfo::None));
    if(strcmp(name, "NONE") == 0)
        return PyInt_FromLong(long(PickVarInfo::None));

    if(strcmp(name, "miscMessage") == 0)
        return PickVarInfo_GetMiscMessage(self, NULL);
    if(strcmp(name, "numMatsPerZone") == 0)
        return PickVarInfo_GetNumMatsPerZone(self, NULL);
    if(strcmp(name, "matNames") == 0)
        return PickVarInfo_GetMatNames(self, NULL);
    if(strcmp(name, "numSpecsPerMat") == 0)
        return PickVarInfo_GetNumSpecsPerMat(self, NULL);
    if(strcmp(name, "floatFormat") == 0)
        return PickVarInfo_GetFloatFormat(self, NULL);


    // Add a __dict__ answer so that dir() works
    if (!strcmp(name, "__dict__"))
    {
        PyObject *result = PyDict_New();
        for (int i = 0; PyPickVarInfo_methods[i].ml_meth; i++)
            PyDict_SetItem(result,
                PyString_FromString(PyPickVarInfo_methods[i].ml_name),
                PyString_FromString(PyPickVarInfo_methods[i].ml_name));
        return result;
    }

    return Py_FindMethod(PyPickVarInfo_methods, self, name);
}

int
PyPickVarInfo_setattr(PyObject *self, char *name, PyObject *args)
{
    PyObject NULL_PY_OBJ;
    PyObject *obj = &NULL_PY_OBJ;

    if(strcmp(name, "variableName") == 0)
        obj = PickVarInfo_SetVariableName(self, args);
    else if(strcmp(name, "variableType") == 0)
        obj = PickVarInfo_SetVariableType(self, args);
    else if(strcmp(name, "names") == 0)
        obj = PickVarInfo_SetNames(self, args);
    else if(strcmp(name, "values") == 0)
        obj = PickVarInfo_SetValues(self, args);
    else if(strcmp(name, "mixNames") == 0)
        obj = PickVarInfo_SetMixNames(self, args);
    else if(strcmp(name, "mixValues") == 0)
        obj = PickVarInfo_SetMixValues(self, args);
    else if(strcmp(name, "mixVar") == 0)
        obj = PickVarInfo_SetMixVar(self, args);
    else if(strcmp(name, "centering") == 0)
        obj = PickVarInfo_SetCentering(self, args);
    else if(strcmp(name, "miscMessage") == 0)
        obj = PickVarInfo_SetMiscMessage(self, args);
    else if(strcmp(name, "numMatsPerZone") == 0)
        obj = PickVarInfo_SetNumMatsPerZone(self, args);
    else if(strcmp(name, "matNames") == 0)
        obj = PickVarInfo_SetMatNames(self, args);
    else if(strcmp(name, "numSpecsPerMat") == 0)
        obj = PickVarInfo_SetNumSpecsPerMat(self, args);
    else if(strcmp(name, "floatFormat") == 0)
        obj = PickVarInfo_SetFloatFormat(self, args);

    if (obj != NULL && obj != &NULL_PY_OBJ)
        Py_DECREF(obj);

    if (obj == &NULL_PY_OBJ)
    {
        obj = NULL;
        PyErr_Format(PyExc_NameError, "name '%s' is not defined", name);
    }
    else if (obj == NULL && !PyErr_Occurred())
        PyErr_Format(PyExc_RuntimeError, "unknown problem with '%s'", name);

    return (obj != NULL) ? 0 : -1;
}

static int
PickVarInfo_print(PyObject *v, FILE *fp, int flags)
{
    PickVarInfoObject *obj = (PickVarInfoObject *)v;
    fprintf(fp, "%s", PyPickVarInfo_ToString(obj->data, "",false).c_str());
    return 0;
}

PyObject *
PickVarInfo_str(PyObject *v)
{
    PickVarInfoObject *obj = (PickVarInfoObject *)v;
    return PyString_FromString(PyPickVarInfo_ToString(obj->data,"", false).c_str());
}

//
// The doc string for the class.
//
#if PY_MAJOR_VERSION > 2 || (PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION >= 5)
static const char *PickVarInfo_Purpose = "This class contains PickVarInfo.";
#else
static char *PickVarInfo_Purpose = "This class contains PickVarInfo.";
#endif

//
// Python Type Struct Def Macro from Py2and3Support.h
//
//         VISIT_PY_TYPE_OBJ( VPY_TYPE,
//                            VPY_NAME,
//                            VPY_OBJECT,
//                            VPY_DEALLOC,
//                            VPY_PRINT,
//                            VPY_GETATTR,
//                            VPY_SETATTR,
//                            VPY_STR,
//                            VPY_PURPOSE,
//                            VPY_RICHCOMP,
//                            VPY_AS_NUMBER)

//
// The type description structure
//

VISIT_PY_TYPE_OBJ(PickVarInfoType,         \
                  "PickVarInfo",           \
                  PickVarInfoObject,       \
                  PickVarInfo_dealloc,     \
                  PickVarInfo_print,       \
                  PyPickVarInfo_getattr,   \
                  PyPickVarInfo_setattr,   \
                  PickVarInfo_str,         \
                  PickVarInfo_Purpose,     \
                  PickVarInfo_richcompare, \
                  0); /* as_number*/

//
// Helper function for comparing.
//
static PyObject *
PickVarInfo_richcompare(PyObject *self, PyObject *other, int op)
{
    // only compare against the same type 
    if ( Py_TYPE(self) != &PickVarInfoType
         || Py_TYPE(other) != &PickVarInfoType)
    {
        Py_INCREF(Py_NotImplemented);
        return Py_NotImplemented;
    }

    PyObject *res = NULL;
    PickVarInfo *a = ((PickVarInfoObject *)self)->data;
    PickVarInfo *b = ((PickVarInfoObject *)other)->data;

    switch (op)
    {
       case Py_EQ:
           res = (*a == *b) ? Py_True : Py_False;
           break;
       case Py_NE:
           res = (*a != *b) ? Py_True : Py_False;
           break;
       default:
           res = Py_NotImplemented;
           break;
    }

    Py_INCREF(res);
    return res;
}

//
// Helper functions for object allocation.
//

static PickVarInfo *defaultAtts = 0;
static PickVarInfo *currentAtts = 0;

static PyObject *
NewPickVarInfo(int useCurrent)
{
    PickVarInfoObject *newObject;
    newObject = PyObject_NEW(PickVarInfoObject, &PickVarInfoType);
    if(newObject == NULL)
        return NULL;
    if(useCurrent && currentAtts != 0)
        newObject->data = new PickVarInfo(*currentAtts);
    else if(defaultAtts != 0)
        newObject->data = new PickVarInfo(*defaultAtts);
    else
        newObject->data = new PickVarInfo;
    newObject->owns = true;
    newObject->parent = 0;
    return (PyObject *)newObject;
}

static PyObject *
WrapPickVarInfo(const PickVarInfo *attr)
{
    PickVarInfoObject *newObject;
    newObject = PyObject_NEW(PickVarInfoObject, &PickVarInfoType);
    if(newObject == NULL)
        return NULL;
    newObject->data = (PickVarInfo *)attr;
    newObject->owns = false;
    newObject->parent = 0;
    return (PyObject *)newObject;
}

///////////////////////////////////////////////////////////////////////////////
//
// Interface that is exposed to the VisIt module.
//
///////////////////////////////////////////////////////////////////////////////

PyObject *
PickVarInfo_new(PyObject *self, PyObject *args)
{
    int useCurrent = 0;
    if (!PyArg_ParseTuple(args, "i", &useCurrent))
    {
        if (!PyArg_ParseTuple(args, ""))
            return NULL;
        else
            PyErr_Clear();
    }

    return (PyObject *)NewPickVarInfo(useCurrent);
}

//
// Plugin method table. These methods are added to the visitmodule's methods.
//
static PyMethodDef PickVarInfoMethods[] = {
    {"PickVarInfo", PickVarInfo_new, METH_VARARGS},
    {NULL,      NULL}        /* Sentinel */
};

static Observer *PickVarInfoObserver = 0;

std::string
PyPickVarInfo_GetLogString()
{
    std::string s("PickVarInfo = PickVarInfo()\n");
    if(currentAtts != 0)
        s += PyPickVarInfo_ToString(currentAtts, "PickVarInfo.", true);
    return s;
}

static void
PyPickVarInfo_CallLogRoutine(Subject *subj, void *data)
{
    typedef void (*logCallback)(const std::string &);
    logCallback cb = (logCallback)data;

    if(cb != 0)
    {
        std::string s("PickVarInfo = PickVarInfo()\n");
        s += PyPickVarInfo_ToString(currentAtts, "PickVarInfo.", true);
        cb(s);
    }
}

void
PyPickVarInfo_StartUp(PickVarInfo *subj, void *data)
{
    if(subj == 0)
        return;

    currentAtts = subj;
    PyPickVarInfo_SetDefaults(subj);

    //
    // Create the observer that will be notified when the attributes change.
    //
    if(PickVarInfoObserver == 0)
    {
        PickVarInfoObserver = new ObserverToCallback(subj,
            PyPickVarInfo_CallLogRoutine, (void *)data);
    }

}

void
PyPickVarInfo_CloseDown()
{
    delete defaultAtts;
    defaultAtts = 0;
    delete PickVarInfoObserver;
    PickVarInfoObserver = 0;
}

PyMethodDef *
PyPickVarInfo_GetMethodTable(int *nMethods)
{
    *nMethods = 1;
    return PickVarInfoMethods;
}

bool
PyPickVarInfo_Check(PyObject *obj)
{
    return (obj->ob_type == &PickVarInfoType);
}

PickVarInfo *
PyPickVarInfo_FromPyObject(PyObject *obj)
{
    PickVarInfoObject *obj2 = (PickVarInfoObject *)obj;
    return obj2->data;
}

PyObject *
PyPickVarInfo_New()
{
    return NewPickVarInfo(0);
}

PyObject *
PyPickVarInfo_Wrap(const PickVarInfo *attr)
{
    return WrapPickVarInfo(attr);
}

void
PyPickVarInfo_SetParent(PyObject *obj, PyObject *parent)
{
    PickVarInfoObject *obj2 = (PickVarInfoObject *)obj;
    obj2->parent = parent;
}

void
PyPickVarInfo_SetDefaults(const PickVarInfo *atts)
{
    if(defaultAtts)
        delete defaultAtts;

    defaultAtts = new PickVarInfo(*atts);
}

